package org.soc.timesheet.controller;

import org.soc.timesheet.domain.CustomersEnabled;
import org.soc.timesheet.domain.Functions;
import org.soc.timesheet.domain.Projects;
import org.soc.timesheet.domain.Roles;
import org.soc.timesheet.domain.SubFunctions;
import org.soc.timesheet.domain.SubProjects;
import org.soc.timesheet.domain.Timesheet;
import org.soc.timesheet.domain.Users;
import org.soc.timesheet.domain.UsersLogged;
import org.soc.timesheet.domain.UsersProject;
import org.soc.timesheet.server.domain.service.CustomersEnabledService;
import org.soc.timesheet.server.domain.service.FunctionsService;
import org.soc.timesheet.server.domain.service.ProjectsService;
import org.soc.timesheet.server.domain.service.RolesService;
import org.soc.timesheet.server.domain.service.SubFunctionsService;
import org.soc.timesheet.server.domain.service.SubProjectsService;
import org.soc.timesheet.server.domain.service.TimesheetService;
import org.soc.timesheet.server.domain.service.UsersLoggedService;
import org.soc.timesheet.server.domain.service.UsersProjectService;
import org.soc.timesheet.server.domain.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.core.convert.converter.Converter;
import org.springframework.format.FormatterRegistry;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;
import org.springframework.roo.addon.web.mvc.controller.converter.RooConversionService;

@Configurable
/**
 * A central place to register application converters and formatters. 
 */
@RooConversionService
public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {

	@Override
	protected void installFormatters(FormatterRegistry registry) {
		super.installFormatters(registry);
		// Register application converters and formatters
	}

	@Autowired
    CustomersEnabledService customersEnabledService;

	@Autowired
    FunctionsService functionsService;

	@Autowired
    ProjectsService projectsService;

	@Autowired
    RolesService rolesService;

	@Autowired
    SubFunctionsService subFunctionsService;

	@Autowired
    SubProjectsService subProjectsService;

	@Autowired
    TimesheetService timesheetService;

	@Autowired
    UsersService usersService;

	@Autowired
    UsersLoggedService usersLoggedService;

	@Autowired
    UsersProjectService usersProjectService;

	public Converter<CustomersEnabled, String> getCustomersEnabledToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.CustomersEnabled, java.lang.String>() {
            public String convert(CustomersEnabled customersEnabled) {
                return new StringBuilder().append(customersEnabled.getCustomerKey()).append(' ').append(customersEnabled.getCustomerDesc()).toString();
            }
        };
    }

	public Converter<Integer, CustomersEnabled> getIdToCustomersEnabledConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Integer, org.soc.timesheet.domain.CustomersEnabled>() {
            public org.soc.timesheet.domain.CustomersEnabled convert(java.lang.Integer id) {
                return customersEnabledService.findCustomersEnabled(id);
            }
        };
    }

	public Converter<String, CustomersEnabled> getStringToCustomersEnabledConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.CustomersEnabled>() {
            public org.soc.timesheet.domain.CustomersEnabled convert(String id) {
                return getObject().convert(getObject().convert(id, Integer.class), CustomersEnabled.class);
            }
        };
    }

	public Converter<Functions, String> getFunctionsToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.Functions, java.lang.String>() {
            public String convert(Functions functions) {
                return new StringBuilder().append(functions.getDescFunction()).toString();
            }
        };
    }

	public Converter<Integer, Functions> getIdToFunctionsConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Integer, org.soc.timesheet.domain.Functions>() {
            public org.soc.timesheet.domain.Functions convert(java.lang.Integer id) {
                return functionsService.findFunctions(id);
            }
        };
    }

	public Converter<String, Functions> getStringToFunctionsConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.Functions>() {
            public org.soc.timesheet.domain.Functions convert(String id) {
                return getObject().convert(getObject().convert(id, Integer.class), Functions.class);
            }
        };
    }

	public Converter<Projects, String> getProjectsToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.Projects, java.lang.String>() {
            public String convert(Projects projects) {
                return new StringBuilder().append(projects.getDescProject()).toString();
            }
        };
    }

	public Converter<Integer, Projects> getIdToProjectsConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Integer, org.soc.timesheet.domain.Projects>() {
            public org.soc.timesheet.domain.Projects convert(java.lang.Integer id) {
                return projectsService.findProjects(id);
            }
        };
    }

	public Converter<String, Projects> getStringToProjectsConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.Projects>() {
            public org.soc.timesheet.domain.Projects convert(String id) {
                return getObject().convert(getObject().convert(id, Integer.class), Projects.class);
            }
        };
    }

	public Converter<Roles, String> getRolesToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.Roles, java.lang.String>() {
            public String convert(Roles roles) {
                return new StringBuilder().append(roles.getCodRole()).append(' ').append(roles.getDescRole()).toString();
            }
        };
    }

	public Converter<Integer, Roles> getIdToRolesConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Integer, org.soc.timesheet.domain.Roles>() {
            public org.soc.timesheet.domain.Roles convert(java.lang.Integer id) {
                return rolesService.findRoles(id);
            }
        };
    }

	public Converter<String, Roles> getStringToRolesConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.Roles>() {
            public org.soc.timesheet.domain.Roles convert(String id) {
                return getObject().convert(getObject().convert(id, Integer.class), Roles.class);
            }
        };
    }

	public Converter<SubFunctions, String> getSubFunctionsToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.SubFunctions, java.lang.String>() {
            public String convert(SubFunctions subFunctions) {
                return new StringBuilder().append(subFunctions.getDescSubFunctions()).toString();
            }
        };
    }

	public Converter<Integer, SubFunctions> getIdToSubFunctionsConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Integer, org.soc.timesheet.domain.SubFunctions>() {
            public org.soc.timesheet.domain.SubFunctions convert(java.lang.Integer id) {
                return subFunctionsService.findSubFunctions(id);
            }
        };
    }

	public Converter<String, SubFunctions> getStringToSubFunctionsConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.SubFunctions>() {
            public org.soc.timesheet.domain.SubFunctions convert(String id) {
                return getObject().convert(getObject().convert(id, Integer.class), SubFunctions.class);
            }
        };
    }

	public Converter<SubProjects, String> getSubProjectsToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.SubProjects, java.lang.String>() {
            public String convert(SubProjects subProjects) {
                return new StringBuilder().append(subProjects.getDescSubProject()).append(' ').append(subProjects.getStartDate()).append(' ').append(subProjects.getEndDate()).toString();
            }
        };
    }

	public Converter<Integer, SubProjects> getIdToSubProjectsConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Integer, org.soc.timesheet.domain.SubProjects>() {
            public org.soc.timesheet.domain.SubProjects convert(java.lang.Integer id) {
                return subProjectsService.findSubProjects(id);
            }
        };
    }

	public Converter<String, SubProjects> getStringToSubProjectsConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.SubProjects>() {
            public org.soc.timesheet.domain.SubProjects convert(String id) {
                return getObject().convert(getObject().convert(id, Integer.class), SubProjects.class);
            }
        };
    }

	public Converter<Timesheet, String> getTimesheetToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.Timesheet, java.lang.String>() {
            public String convert(Timesheet timesheet) {
                return new StringBuilder().append(timesheet.getData()).append(' ').append(timesheet.getStartHour()).append(' ').append(timesheet.getStartMin()).append(' ').append(timesheet.getEndHour()).toString();
            }
        };
    }

	public Converter<String, Timesheet> getIdToTimesheetConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.Timesheet>() {
            public org.soc.timesheet.domain.Timesheet convert(java.lang.String id) {
                return timesheetService.findTimesheet(id);
            }
        };
    }

	public Converter<Users, String> getUsersToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.Users, java.lang.String>() {
            public String convert(Users users) {
                return new StringBuilder().append(users.getLogin()).toString();
            }
        };
    }

	public Converter<Integer, Users> getIdToUsersConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.Integer, org.soc.timesheet.domain.Users>() {
            public org.soc.timesheet.domain.Users convert(java.lang.Integer id) {
                return usersService.findUsers(id);
            }
        };
    }

	public Converter<String, Users> getStringToUsersConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.Users>() {
            public org.soc.timesheet.domain.Users convert(String id) {
                return getObject().convert(getObject().convert(id, Integer.class), Users.class);
            }
        };
    }

	public Converter<UsersLogged, String> getUsersLoggedToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.UsersLogged, java.lang.String>() {
            public String convert(UsersLogged usersLogged) {
                return new StringBuilder().append(usersLogged.getLastRequest()).append(' ').append(usersLogged.getLastAccess()).append(' ').append(usersLogged.getToken()).append(' ').append(usersLogged.getSessioId()).toString();
            }
        };
    }

	public Converter<String, UsersLogged> getIdToUsersLoggedConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.UsersLogged>() {
            public org.soc.timesheet.domain.UsersLogged convert(java.lang.String id) {
                return usersLoggedService.findUsersLogged(id);
            }
        };
    }

	public Converter<UsersProject, String> getUsersProjectToStringConverter() {
        return new org.springframework.core.convert.converter.Converter<org.soc.timesheet.domain.UsersProject, java.lang.String>() {
            public String convert(UsersProject usersProject) {
                return "(no displayable fields)";
            }
        };
    }

	public Converter<String, UsersProject> getIdToUsersProjectConverter() {
        return new org.springframework.core.convert.converter.Converter<java.lang.String, org.soc.timesheet.domain.UsersProject>() {
            public org.soc.timesheet.domain.UsersProject convert(java.lang.String id) {
                return usersProjectService.findUsersProject(id);
            }
        };
    }

	public void installLabelConverters(FormatterRegistry registry) {
        registry.addConverter(getCustomersEnabledToStringConverter());
        registry.addConverter(getIdToCustomersEnabledConverter());
        registry.addConverter(getStringToCustomersEnabledConverter());
        registry.addConverter(getFunctionsToStringConverter());
        registry.addConverter(getIdToFunctionsConverter());
        registry.addConverter(getStringToFunctionsConverter());
        registry.addConverter(getProjectsToStringConverter());
        registry.addConverter(getIdToProjectsConverter());
        registry.addConverter(getStringToProjectsConverter());
        registry.addConverter(getRolesToStringConverter());
        registry.addConverter(getIdToRolesConverter());
        registry.addConverter(getStringToRolesConverter());
        registry.addConverter(getSubFunctionsToStringConverter());
        registry.addConverter(getIdToSubFunctionsConverter());
        registry.addConverter(getStringToSubFunctionsConverter());
        registry.addConverter(getSubProjectsToStringConverter());
        registry.addConverter(getIdToSubProjectsConverter());
        registry.addConverter(getStringToSubProjectsConverter());
        registry.addConverter(getTimesheetToStringConverter());
        registry.addConverter(getIdToTimesheetConverter());
        registry.addConverter(getUsersToStringConverter());
        registry.addConverter(getIdToUsersConverter());
        registry.addConverter(getStringToUsersConverter());
        registry.addConverter(getUsersLoggedToStringConverter());
        registry.addConverter(getIdToUsersLoggedConverter());
        registry.addConverter(getUsersProjectToStringConverter());
        registry.addConverter(getIdToUsersProjectConverter());
    }

	public void afterPropertiesSet() {
        super.afterPropertiesSet();
        installLabelConverters(getObject());
    }
}
